<script>
	var url;
	$(document).ready(function(){
		//print
		
		/*print = function (){
				
				url:base_url+'khs/pdf/'+$('#s_kd_fakultas').val()+'/'+$('#s_kd_prodi').val()+'/'+$('#s_tahun').val()+'/'+$('#nim').combogrid('getValue');
		}*/
		
		//load mahasiswa
		load_mahasiswa = function(){
			$('#nim').combogrid({
				panelWidth:450,
				panelHeight:275,
				value:'<?=$this->session->userdata('username'); ?>',
			 
				idField:'nim',
				textField:'nama',
				url:base_url+'prosedur/getMahasiswa/'+$('#s_kd_prodi').val(),
				columns:[[
					{field:'nim',title:'NIM',width:130},
					{field:'nama',title:'Nama',width:250}
				]],
				onChange: function(value){
					//getsemester();
				}
			});
		}
		
		// load grid
		$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>khs/grid"});	
			//$('#dg').datagrid('enableFilter'); 			
		});
		
		// onchange
		$('#s_kd_fakultas').change(function(){
			$('#s_kd_prodi').load(base_url+'prosedur/getProdibyFakultas/'+$('#s_kd_fakultas').val());
		});
		$('#s_kd_prodi').change(function(){
			//$('#kd_kurikulum').load(base_url+'prosedur/getKurikulumbyProdi/'+$('#s_kd_prodi').val());
			load_mahasiswa();
		});
		load_mahasiswa();
		
		// filter
		filter = function(){
			$('#dg').datagrid('load',{
				kd_fakultas : $('#s_kd_fakultas').val(),
				kd_prodi : $('#s_kd_prodi').val(),
				tahun : $('#s_tahun').val(),
				nim : $('#nim').combogrid('getValue')
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		// export
		exportPDF = function(){
			var kd_fakultas = $('#s_kd_fakultas').val();
			var kd_prodi = $('#s_kd_prodi').val();
			var tahun = $('#s_tahun').val();
			var nim = $('#nim').combogrid('getValue');
			if (kd_fakultas != '' && kd_prodi != '' && tahun != '' && nim != ''){
				window.open('<?=base_url().'khs/laporan_pdf/'?>'+kd_fakultas+'/'+kd_prodi+'/'+tahun+'/'+nim);
			}else{
				$.messager.show({
				title: 'Warning',
				msg: 'Harap Isi Filter Terlabih Dahulu'
				});
			}
			//$('#dg').datagrid('enableFilter');
		}
		
		//# Tombol Bawah
		$(function(){
			var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
					{
						iconCls:'icon-print',
						text:'Export PDF',
						handler:function(){
							var kd_fakultas = $('#s_kd_fakultas').val();
							var kd_prodi = $('#s_kd_prodi').val();
							var tahun = $('#s_tahun').val();
							var nim = $('#nim').combogrid('getValue');
							window.open('<?=base_url().'khs/pdf/'?>'+kd_fakultas+'/'+kd_prodi+'/'+tahun+'/'+nim);
						}
					}
				]
			});			
		});
	
	});
</script>
<table id="dg" title="Kartu Hasil Studi " data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:false,
			pageSize:30,
			fit:false,
			fitColumns:true,
			cache:false,
			showFooter:true,
			toolbar:'#toolbar'
			">
<!--
<table id="dg" class="easyui-treegrid"  data-options="
			rownumbers:true,
			singleSelect:true,
			collapsible:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			toolbar:'#toolbar',
			view:groupview,
			groupField:'nim',
			">			
-->						
	<thead>
		<tr>
			<!--<th field="tahun_penerimaan" sortable="true" width="80">Tahun Penerimaan</th> -->
			<th field="kd_matakuliah" sortable="true" width="100">Kode MK</th>
			<th field="nama_matakuliah" sortable="true" width="100">Nama Matakuliah</th>
			<th field="sks" sortable="true" width="150">SKS</th>
			<th field="semester" sortable="true" width="100">Semester</th>
			<th field="nilai_huruf" sortable="true" width="100">Nilai</th>
			<!--<th field="ips1" sortable="true" width="100">IPS</th>-->
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<div class="fsearch">
		<table width="700" border="0">
		  <tr>
			<td>Fakultas</td>
			<td>: 
				<select id="s_kd_fakultas" name="kd_fakultas" style="width:220px;">
					<?=$this->mdl_prosedur->OptionFakultas();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>Mahasiswa</td>
			<td>: 
				<input type="textfield" id="nim" name="nim" size="33" value="">
			</td>
		  </tr>
		  <tr>
			<td>Program Studi</td>
			<td>: 
				<select id="s_kd_prodi" name="kd_prodi" style="width:220px;">
					<?=$this->mdl_prosedur->OptionProdi();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td></td>
			<td> 
				
			</td>
		  </tr>
		  <tr>
			<td>Tahun Ajaran</td>
			<td>: 
				<select id="s_tahun" name="s_tahun" style="width:220px;">
					<?=$this->mdl_prosedur->OptionTahunAjaran();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td></td>
			<td> 
				<a href="#" onclick="filter()" class="easyui-linkbutton" iconCls="icon-search">Load</a>
				<a href="#" onclick="exportPDF()" class="easyui-linkbutton" iconCls="icon-print">Export PDF</a>
			</td>
		  </tr>
		</table>
	</div>
</div>

